<?php

// Quick Import file
function import($path) {
    $path=str_replace('.','/',$path);
    $path.='.php';
    include $path;
}

// Redirect Url
function url($url) {
    header('location:'.$url);
}

// Load Page Module
function load($module) {
    global $sql;
    $modules=$sql->get('module');
}

// JSON Data
function json($info) {
    return '{"results":'.json_encode($info).'}';
}

// Get File Extension
function file_ext($str){
    $str='.'.$str;
    $ext='';
    $i=strlen($str);
    while ($str[$i]!='.') {
        $ext=$str[$i].$ext;
        $i--;
    }
    return $ext;
}

// Debug Variable
function bug($var,$die=true){
    echo '<pre>';
    print_r($var);
    echo '</pre>';
    if ($die) die();
}

// Compress Data (JS,CSS,HTML)
function compress($content,$type='html') {
    switch ($type) {
        case 'css':
            /* Rules
                1. from } to character
                2. from { to character
                3. from ; to character
                4. from character to {
                5. remove any comment
                6.group properties to margin-padding
            */
            return $content;
            break;
        case 'js':

            return $content;
            break;
        default:
            return $content;
            break;
    }
}

function remote_file_size($link) {
    $remoteFile=$link;
    $ch = curl_init($remoteFile);
    curl_setopt($ch, CURLOPT_NOBODY,true);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch,CURLOPT_HEADER, true);
    curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
    $data=curl_exec($ch);
    curl_close($ch);$contentLength='Unknown';
    (preg_match('/Content-Length: (\d+)/', $data,$matches))?$contentLength=round(((int)$matches[1])/1024/1024,2):'';
    return $contentLength;
}

function download($filename,$filepath,$mimetype) {
    header('Cache-Control: ');
    header('Content-Description: File Transfer');
    header('Content-Disposition: attachment; filename='.$filename);
    header('Content-Type:'.$mimetype);
    header('Content-Transfer-Encoding: binary');
    return readfile($filepath);
}









